package com.ck567.netty.chatroom.config

import com.ck567.netty.chatroom.protocol.Serializer
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import java.util.*

@Component
class Config {

    @Value("\${serializer.algorithm}")
    fun setIsDebug(serializerAlgorithm: String) {
        Config.serializerAlgorithm = serializerAlgorithm
    }

    companion object {
        private var serializerAlgorithm:String ?= null
        var properties: Properties? = null
        fun getServerPort(): Int {
            val value = properties!!.getProperty("server.port")
            return value?.toInt() ?: 8080
        }

        fun getSerializerAlgorithm(): Serializer.Algorithm {
            val value = serializerAlgorithm
            return if (value == null) {
                Serializer.Algorithm.Java
            } else {
                Serializer.Algorithm.valueOf(value)
            }
        }

    }
}